package com.zhiyou100.cudr;

import com.zhiyou100.dao.StudentDao;
import com.zhiyou100.entityclass.Student;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

/**
 * @packageName: ${NAME}
 * @className: ${PACKAGE_NAME}
 * @Description: TODO 获取所有
 * @author: yang
 * @date: 7/22/20
 */
@WebServlet(name = "GetAll", urlPatterns = "/getAll")
public class GetAll extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        // 设定编码集
        response.setContentType("text/html;charset=UTF-8");
        // 设定类型
        StudentDao studentDao = new StudentDao();
        ArrayList<Student> allStudent = studentDao.getAllStudent();
        // 放入 Session 域中
        request.getSession().setAttribute("allStudent",allStudent);
        response.sendRedirect(request.getContextPath()+"/jsp/getAll.jsp");

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
